﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CardLogistics.Web.Components;
using System.Text;

namespace CardLogistics.Web.MainPage.CardArrival.OrderArrivalBook
{
    public partial class ListInfo : BasePage
    {
        private static readonly CardLogistics.DAL.CardArrival.OrderArrivalBookData dal = new DAL.CardArrival.OrderArrivalBookData();
        protected void Page_Load(object sender, EventArgs e)
        {
            WebUserControl_ToolBar1.DeleteEvent += new EventHandler(WebUserControl_ToolBar1_DeleteEvent);
            if (!IsPostBack)
            {
                BindRpt(0);
            }
        }

        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void WebUserControl_ToolBar1_DeleteEvent(object sender, EventArgs e)
        {
            string delId = hdf_Id.Value;
            if (!string.IsNullOrEmpty(delId))
            {
                string[] ids = delId.TrimEnd(',').Split(',');
                int resCount = 0;
                for (int i = 0; i < ids.Length; i++)
                {
                    string resStr = dal.Delete(ids[i]);
                    if (resStr.Split(',')[0] == "ok")
                        resCount++;
                }
                ShowMessageBox("共选中" + ids.Length + "条数据,删除成功" + resCount + "条！");
                BindRpt(0);
            }
        }

        /// <summary>
        /// 绑定Rpt数据
        /// </summary>
        private void BindRpt(int pageIndex)
        {
            int recordCount = 0;
            int pageCount = 0;
            StringBuilder sbStr = new StringBuilder();
            sbStr.Append(" 1=1 ");
            if (txt_OrderNo.Text.Trim().Length > 0)
                sbStr.Append(" and OrderNo like '%" + txt_OrderNo.Text.Trim() + "%' ");//订单编号
            if (txt_CheckNo.Text.Trim().Length > 0)
                sbStr.Append(" and CheckNo like '%" + txt_CheckNo.Text.Trim() + "%' ");//入库单号

            if (txt_StartOrderData.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(OrderDate,'yyyy-MM-dd')>='" + txt_StartOrderData.Text.Trim() + "'");//订单开始日期
            if (txt_EndOrderData.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(OrderDate,'yyyy-MM-dd')<='" + txt_EndOrderData.Text.Trim() + "'");//订单结束日期

            if (txt_StartStorageDate.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(GetData,'yyyy-MM-dd')>='" + txt_StartStorageDate.Text.Trim() + "'");//入库开始日期
            if (txt_EndStorageDate.Text.Trim().Length > 0)
                sbStr.Append(" and to_char(StorageDate,'yyyy-MM-dd')<='" + txt_EndStorageDate.Text.Trim() + "'");//入库结束日期

            DataTable dt = CardLogistics.DAL.CommonData.QuickPage_Oracle("v_OrderArrivalBook", "ID", " StorageDate ", AspNetPager1.PageSize, pageIndex, sbStr.ToString(), "*", out pageCount, out recordCount);

            if (dt.Rows.Count == 0 && pageIndex ==1)
            {
                 ShowMessageBox("没有查询到符合条件的记录！");
            }
            SetNetPagerHtml(AspNetPager1, dt, rptList, recordCount);
        }


        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            WebPageIndex = AspNetPager1.CurrentPageIndex;
            BindRpt(AspNetPager1.CurrentPageIndex);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            BindRpt(1);
        }
    }
}